package optional;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.junit.Test;

import java.util.Optional;

/**
 * Author:ZouHeng
 * Description:
 * Date:2021-07-06  16:28
 **/
public class TestOptional {

    @Getter
    @Setter
    @AllArgsConstructor
    public class User {
        private String name;
        private Integer age;
    }

    @Test
    public void testOptional() {
        User user = null;
        User user1 = new User("kobe", 38);
        String msg = Optional.ofNullable(user1).map(s -> s.getName()).orElse("UNKNOW");
        System.out.println(msg);
    }
}
